<?php

namespace app\controller;


use app\BaseController;
use app\model\Company;
use app\traits\CommonTrait;
use app\validate\CompanyStore;
use app\validate\UserStore;
use think\exception\ValidateException;
use think\facade\Request;


class AdminCompany extends BaseController
{
    use CommonTrait;

    public function store()
    {
        $companyData = [
            'name'=>Request::post('name'),
            'desc'=>Request::post('desc'),
            'employee_num'=>Request::post('employee_num'),
            'charge_person'=>Request::post('charge_person'),
            'charge_person_phone'=>Request::post('charge_person_phone')
        ];
        try {
            validate(CompanyStore::class)->check($companyData);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return $this->apiJson(-1, $e->getMessage());
        }
        Company::create($companyData);
        return $this->apiJson(1,'success');
    }

    public function list()
    {
        $list = Company::field('id,name,desc,employee_num,charge_person,charge_person_phone,status,create_time')->select();
        return $this->apiJson(1,'success',$list);
    }

}